import { Popconfirm, Popover } from 'antd';

const columnConfig = {
  sort: {
    name: '序号',
    code: 'sort',
    width: 60,
    render(v, r, i) {
      return i + 1;
    }
  },
  name: {
    name: "寄件人",
    code: "name",
    width: 80,
    render: (text) => <span className='common-color3'>{text}</span>
  },
  fullAddress: {
    name: "地址",
    code: "fullAddress",
    width: 200,
  },
  mobPhone: {
    name: "手机",
    code: "mobPhone",
    width: 120,
    render: (text) => <span className='common-color3'>{text}</span>
  },
  telPhone: {
    name: "座机",
    code: "telPhone",
    width: 120,
  },
  isDefault: {
    name: "默认",
    code: "isDefault",
    width: 80,
    render: (text) => (text == 1 ? '是' : '否'),
  },
  opera: {
    name: "操作",
    code: "opera",
    width: 200,
    lock: true,
  }
}

//渲染操作列
const RenderOpera = ({ handleOpera, record }) => {
  return (
    <span className="opera-span-common">
      <Popconfirm
        title={record.isDefault == 1 ? '确定取消默认?' : '确定设为默认?'}
        onConfirm={() => handleOpera('status', record)}
        okText="确定"
        cancelText="取消"
      >
        <span>{record.isDefault == 1 ? '取消默认' : '设为默认'}</span>
      </Popconfirm>
      <i>|</i>
      <span onClick={() => handleOpera('edit', record)}>编辑</span>
      <i>|</i>
      <Popconfirm
        title="确定要删除吗?"
        onConfirm={() => handleOpera('delete', record)}
        okText="确定"
        cancelText="取消"
      >
        <span>删除</span>
      </Popconfirm>
    </span>
  )
}

//获取列数据
export const getColumns = ({ handleOpera }) => {
  const arr = [];
  Object.keys(columnConfig).map(v => {
    const item = columnConfig[v];
    if (v == 'opera') {
      item.render = (t, r) => <RenderOpera handleOpera={handleOpera} record={r} />;
    }
    arr.push(item);
  })
  return arr;
}